package com.example.server.imp;

import com.example.dao.Studentdao;
import com.example.pojo.Student;
import com.example.server.StudentServer;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils;

import java.util.List;

@Service
@Transactional(timeout=1)
public class StudentSercverimp implements StudentServer {
    @Autowired
    private Studentdao studentdao;
    /*
    搜索加分页
     */

    @Override
    public List<Student> Queryall() {
        return studentdao.Queryall();
    }

    @Override
    public PageInfo<Student> querall(Integer pageNum,Integer pageSize,String name) {
        PageHelper.startPage(pageNum,pageSize);
        if (StringUtils.isEmpty(name)){
            List<Student> queryall = studentdao.Queryall();
            PageInfo<Student> pageInfo=new PageInfo<>(queryall);
           return pageInfo;
        }else{
            List<Student> fuzzyquery = studentdao.Fuzzyquery(name);
            PageInfo<Student> pageInfo1=new PageInfo<>(fuzzyquery);
            return pageInfo1;
        }

    }
    /*
    删除
     */
   @Transactional(noRollbackFor = NoSuchFieldException.class)
    @Override
    public int Deleteaccordingtoid(int id) throws NoSuchFieldException {
       int i=0;
       try {
            i = studentdao.Deleteaccordingtoid(id);
          
       } catch (Exception e) {
           e.printStackTrace();
       }
       return i;
   }


/*
修改
 */
    @Override
    public int Increasedata(Student student) {
        return studentdao.Increasedata(student);
    }
    /*
    根据id修改数据
     */

    @Override
    public int changethedata(Student student) {
        return studentdao.changethedata(student);
    }
}
